<?php

require_once("KsiegaGosciSQLAndEmail.php");

class KsiegaGosciSQL extends KsiegaGosci  {
	private $link;
	
	public function __construct(){
		$this->link = mysql_connect("localhost", "root", "")
		or die("<b>Blad polaczenia z baza danych</b><br />");
		mysql_select_db("guestbook_db")
		or die("<b>Nie znaleziono bazy danych na serwerze.</b><br />");
	}
	
	public function odczytaj(){
		$query  = "SELECT * FROM guestbook";
		$result = mysql_query($query)
		or die("Blad pobrania wpisow z bazy.");
		$return = '<table BORDER="1">';
		while ($row = mysql_fetch_array($result)) {
			$return .= "<TR><TD>" . $row["WPIS"] .
				 "</TD></TR>\n";
		}
		$return .= "</table>";
		mysql_free_result($result);	
		return $return;
	}
	public function zapisz($wpis){ 
		$sql = "INSERT INTO `guestbook` (`ID`, `WPIS`) VALUES (NULL, '".$wpis."');";
		mysql_query($sql)
		or die("Blad zapisu wpisow do bazy.");
	}
	public function usunWszystko(){
		$query  = "DELETE FROM guestbook";
		$result = mysql_query($query)
		or die("Blad usuwania wpisow z bazy.");
	}
}
?>